package com.zjw.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zjw.annotation.domain.entity.Tag;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 标签(Tag)表数据库访问层
 *
 * @author lkzy
 * @since 2023-12-19 15:00:03
 */
@Mapper
public interface TagMapper extends BaseMapper<Tag> {


    @Select("select * from sg_tag t left join sg_article_tag artt on t.id = artt.tag_id where artt.article_id = #{id}")
    List<Tag> getTagsByArticleId(Long id);

    @Insert("insert into sg_article_tag(article_id, tag_id) values(#{id}, #{tId})")
    void addArticleTag(@Param("id") Long id,@Param("tId") long tId);


    @Delete("delete from sg_article_tag artt where artt.article_id = #{id}")
    void restTags(@Param("id") Long id);
}
